package com.heqiang.spring;

import com.heqiang.spring.config.BeanDefinition;
import com.heqiang.spring.factory.BeanFactory;
import com.heqiang.spring.factory.DefaultListableBeanFactory;
import com.heqiang.spring.service.TestService;


/**
 * 学习链接
 * https://mp.weixin.qq.com/s/CgvQzm8B-CvQvXdxONC-lA
 */
public class TestMain {

    public static void main(String[] args) {
        //创建工厂
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        //注册bean
        BeanDefinition beanDefinition = new BeanDefinition(TestService.class);
        beanFactory.registerBeanDefinition("testService",beanDefinition);
        //获取bean
        TestService testService = (TestService) beanFactory.getBean("testService");
        testService.getInfo();
        //再次获取bean，这次获取的bean就是从单例里拿的
        TestService testService2 = (TestService) beanFactory.getBean("testService");
        testService2.getInfo();

    }
}
